<include file="Common/header" />
<title>会员录入</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
</head>
<body>
<OBJECT id="ML_IDCard" height="0" width="0" classid="clsid:10946843-7507-44FE-ACE8-2B3483D179B7" name="ML_IDCard"></OBJECT>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add" enctype="multipart/form-data">
		<div class="panel panel-primary">
			<div class="panel-header">基本信息</div> 
			<table class="table table-border table-bordered table-striped">
	            <tr>
	                <td style="background-color: #f9f9f9;text-align: right">合同编号：</td>
	                <td style="background-color: white;" colspan="3">
						<input type="text" class="input-text radius" name="contract" id="contract" style="width:180px;" value="{$userinfo['contract']}" />
						<span class="select-box radius" style="width: 180px;">
							<select class="select radius" id="contracts" name="contracts">
								<option value="">--选择合同号--</option>
								<?php foreach($contractlist as $k=>$contract){ ?>
								<option value="{$contract['contract']}">{$contract['contract']}</option>
								<?php } ?>
							</select>
						</span>
						<button type="button" class="btn btn-success radius readcard">
							<i class="icon-ok"></i> 读取身份证
						</button>
						<?php if($userinfo['member_id']){ ?>
						<button type="button" class="btn btn-primary radius guestcard" mid="{$userinfo['member_id']}">
							<i class="icon-ok"></i> 制卡
						</button>
						<?php } ?>
					</td>
					<td style="background-color: #f9f9f9;text-align: right">客人姓名：</td>
	                <td style="background-color: white">
						<input type="hidden" name="member_id" id="member_id" value="{$userinfo['member_id']}" />
						<input type="text" name="member_nick" id="member_nick" class="input-text radius" value="{$userinfo['member_nick']}" />
					</td>
	            </tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">身份证：</td>
	                <td style="background-color: white;">
						<input type="text" name="member_card" id="member_card" class="input-text radius" value="{$userinfo['member_card']}" />
	                </td>
					<td style="background-color: #f9f9f9;text-align: right">联系方式：</td>
	                <td style="background-color: white">
						<input type="text" name="member_phone" id="member_phone" class="input-text radius" value="{$userinfo['member_phone']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">紧急联系人：</td>
	                <td style="background-color: white">
						<input type="text" name="j_name" id="j_name" class="input-text radius" value="{$userinfo['j_name']}" />
					</td>
				</tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">紧急联系方式：</td>
	                <td style="background-color: white">
						<input type="text" name="j_phone" id="j_phone" class="input-text radius" value="{$userinfo['j_phone']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">联系地址：</td>
	                <td style="background-color: white" colspan="3">
						<input type="text" name="address" id="address" class="input-text radius" value="{$userinfo['address']}" />
					</td>
				</tr>
				<tr>	
					<td style="background-color: #f9f9f9;text-align: right">房间号：</td>
					<td style="background-color: white">
						<input type="text" name="room_number" id="room_number" class="input-text radius" value="{$userinfo['room_number']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">租房类型：</td>
					<td style="background-color: white">
						<span class="select-box">
							<select class="select radius" id="type" name="type">
								<option value="长租" selected="">长租</option>
								<option value="短租">短租</option>
							</select>
						</span>
					</td>
					<td style="background-color: #f9f9f9;text-align: right"></td>
					<td></td>
				</tr>
				<tr>	
					<td style="background-color: #f9f9f9;text-align: right">月租：</td>
					<td style="background-color: white">
						<input type="text" name="rent" id="rent" class="input-text radius" value="{$userinfo['rent']}" readonly />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">押金：</td>
					<td style="background-color: white">
						<input type="text" name="deposit" id="deposit" class="input-text radius" value="{$userinfo['deposit']}" readonly />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">物业费：</td>
					<td style="background-color: white">
						<input type="text" name="property" id="property" class="input-text radius" value="{$userinfo['property']}" readonly />
					</td>
				</tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">费用开始时间：</td>
					<td style="background-color: white">
						<input type="text" name="checkin_time" id="checkin_time" class="input-text radius" value="<?php echo !empty($userinfo['checkin_time']) ? date('Y-m-d', $userinfo['checkin_time']) : '';?>" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">房租截止时间：</td>
					<td style="background-color: white">
						<input type="text" name="leaving_time" id="leaving_time" class="input-text radius" value="<?php echo !empty($userinfo['leaving_time']) ? date('Y-m-d', $userinfo['leaving_time']) : '';?>" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">物业截至时间：</td>
					<td style="background-color: white">
						<input type="text" name="property_time" id="property_time" class="input-text radius" value="<?php echo !empty($userinfo['property_time']) ? date('Y-m-d', $userinfo['property_time']) : '';?>" />
					</td>
				</tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">合同开始时间：</td>
					<td style="background-color: white">
						<span class="select-box radius">
							<input type="text" name="btime" id="btime" class="select layer-date radius times" value="<?php echo $userinfo['member_id'] ? date('Y-m-d', $userinfo['btime']) : '';?>" />
						</span>
					</td>
					<td style="background-color: #f9f9f9;text-align: right">合同终止时间：</td>
					<td style="background-color: white">
						<span class="select-box radius">
							<input type="text" name="etime" id="etime" class="select layer-date radius times" value="<?php echo $userinfo['member_id'] ? date('Y-m-d', $userinfo['etime']) : '';?>" />
						</span>
					</td>
					<td style="background-color: #f9f9f9;text-align: right">&nbsp;</td>
					<td style="background-color: white">&nbsp;</td>
				</tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">水表起数：</td>
					<td style="background-color: white">
						<input type="text" name="eqment_1" id="eqment_1" class="input-text radius" value="{$userinfo['eqment_1']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">电表起数：</td>
					<td style="background-color: white">
						<input type="text" name="eqment_2" id="eqment_2" class="input-text radius" value="{$userinfo['eqment_2']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">气表起数：</td>
					<td style="background-color: white">
						<input type="text" name="eqment_3" id="eqment_3" class="input-text radius" value="{$userinfo['eqment_3']}" />
					</td>
				</tr>

				<tr>
					<td style="background-color: #f9f9f9;text-align: right; color: red;">其他费用：</td>
					<td style="background-color: white">
						<input type="text" name="discount" id="discount" class="input-text radius" value="{$userinfo['discount']}" />
					</td>
					<td colspan="2" style="color: red;">
						注：正数为客户需要缴纳的费用，负数为客户享受的额外优惠；
					</td>
					<td style="background-color: #f9f9f9;text-align: right; ">备注：</td>
					<td style="background-color: white">
						<input type="text" name="remark" id="remark" class="input-text radius" value="{$userinfo['remark']}" />
					</td>
				</tr>
				<!--
				<tr>
					<td class="text-c" colspan="6">
						<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
					</td>
				</tr>-->
			</table>
		</div>
		<input type="hidden" name="images" id="images" value="{$userinfo['images']}" />
		<input type="hidden" name="password" id="password" value="" />
	</form>
	<form action="" method="post" class="form form-horizontal" id="uploadform" enctype="multipart/form-data">
		<div class="panel panel-warning">
			<div class="panel-header">上传图片</div>
			<span class="btn-upload form-group mt-5 mb-5 ml-10">
				<input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly="">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont"></i> 浏览文件</a>
				<input type="file" multiple="" name="file[]" class="input-file">
			</span>
			<span class="btn-upload form-group mt-5 mb-5 ml-10">
				<input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly="">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont"></i> 浏览文件</a>
				<input type="file" multiple="" name="file[]" class="input-file">
			</span>
			<span class="btn-upload form-group mt-5 mb-5 ml-10">
				<input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly="">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont"></i> 浏览文件</a>
				<input type="file" multiple="" name="file[]" class="input-file">
			</span>
			<span class="btn-upload form-group mt-5 mb-5 ml-10">
				<input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly="">
				<a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont"></i> 浏览文件</a>
				<input type="file" multiple="" name="file[]" class="input-file">
			</span>
			<button type="button" class="btn btn-success radius uploadBtn">
				<i class="icon-ok"></i> 上传
			</button>
		</div>
		
		<div class="mt-5 mb-5 text-c">
			<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save">
				<i class="icon-ok"></i> 确定
			</button>
		</div>
	</form>
	<div class="panel panel-primary">
		<div class="panel-header">优惠活动</div>
		<div id="eventinfo">
			<include file="Member/eventinfo" />
		</div>
	</div>
	
</div>

<script type="text/javascript" src="__PUBLIC__/h-ui/lib/socket.io/socket.io.js"></script>
<script>
	var load;
	var socket = io.connect("http://mamagy.com:8016?uid="+ "{$Think.session.user_id}");
		socket.on('GuestCardChange', function(data){
			layer.close(load);
			var state = data.state/1 || 0;
			switch(state){
				case -1:
					layer.msg('卡号格式错误', {icon: 5, time: 2000});
				break;
				case 0:
					layer.msg('制卡失败', {icon: 2, time: 2000});
				break;
				case 1:
					layer.msg('制卡成功', {icon: 1, time: 2000}, function(){
						$.get('ajaxcard.html', {
							card: data.cardno,
							lock_id: data.locknum,
							uid: $("#member_id").val(),
						}, function(){});
					});
				break;
			}
		});
		
	$(document).ready(function(){
		//设置时间控件
		$(".time").on('click', function(){
			laydate({istime: true, format: 'YYYY-MM-DD'});
		});

		/**
		 * 判断享受的活动
		 **/
		$(".times").on('click', function(){
			laydate({
				istime: true, 
				format: 'YYYY-MM-DD',
				choose: function(dates){
					var btime = $("#btime").val(),
						etime = $("#etime").val();
					if(btime.length && etime.length){
						$.get('ajaxevent.html', {btime: btime, etime: etime, roomnumber: $("#room_number").val()}, function(data){
							$("#eventinfo").html(data);
						});
					}else{
						//layer.msg('请选择完合同时间', {icon: 5, time: 2000});
					}
				}
			});
		});

		/**
		 * 自动填充押金
		 **/
		$("#room_number").on('input propertychange', function(){
			var roomnumber = $(this).val();
			if(roomnumber.length >= 3){
				//判断是否存在用户
				var member_id = $("#member_id").val() || 0;
				$.get('ajaxeqm.html', {roomnumber: roomnumber}, function(data){
					if(data.errCode/1){
						$("#rent").val(data.rent);
						$("#property").val(data.property);
						$("#deposit").val(data.deposit);
						if(member_id/1 <= 0){
							$("#eqment_1").val(data.eqment_1);
							$("#eqment_2").val(data.eqment_2);
							$("#eqment_3").val(data.eqment_3);
						}
					}
				});
			}else{

			}
		});
		
		//联动事件
		$("#contracts").on('change', function(){
			$("#contract").val($(this).val());
		});
		
		//上传图片
		$(".uploadBtn").on('click', function(){
			var load = layer.load(2);
			$("#uploadform").ajaxSubmit({
				type:'post',
				url:'upload.html',
				success:function(data){
					layer.close(load);
					var data = JSON.parse(data);
					if(data.errCode/1 > 0){
						layer.msg('上传成功', {icon:1, time: 2000});
						$("#images").val(data.errMsg);
					}else{
						layer.msg(data.errMsg, {icon:2, time: 2000});
					}
				},
				error:function(XmlHttpRequest,textStatus,errorThrown){
					
				}
			});
		});

		/**
		 * 读取身份证信息
		 **/
		$(".readcard").on('click', function(){
			//1. 判断浏览器是否是IE内核
			var u = navigator.userAgent;
			if(u.indexOf('Trident') > -1){
				//开始读取身份证信息
				var ret = ML_IDCard.ReadCard();
				if(ret/1 == 0){
					//开始赋值
					$("#member_nick").val(ML_IDCard.Name);
					$("#member_card").val(ML_IDCard.CardNo);
					$("#address").val(ML_IDCard.Address);
				}else{
					layer.msg('读取身份证信息失败', {icon: 5, time: 2000});
				}
			}else{
				layer.msg('请使用IE或IE内核类型的浏览器打开。',{icon: 5, time: 2000});
			}
		});
		
		/**
		 * 制卡
		 **/
		$(".guestcard").on('click', function(){
			load = layer.load(2);
			var userid = $(this).attr('mid');
			//异步请求数据
			$.get('ajax.html',{userid: userid}, function(data){
				if(data.errCode/1){
					//弹出层显示
					var html = "<div>有效时间: "+ data.times +"</div>";
					var i = layer.open({
						title: '制卡提醒',
						content: html,
						yes: function(){
							layer.close(i);
							socket.emit('GuestCard', data.info);
						}
					});
				}else{
					layer.msg(data.errMsg, {icon: 5, time: 2000});
				}
			});
		});
		
		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			if($("#btime").val() == ""){
				layer.msg("请选择合同开始时间", {icon: 2, time:2000});
				return false;
			}
			
			if($("#etime").val() == ""){
				layer.msg("请选择合同截止时间", {icon: 2, time:2000});
				return false;
			}

			var nickname = $("#member_nick").val();
			if(nickname.length > 20){
				layer.msg('姓名长度在1～20个字符之间', {icon: 5, time: 2000});
				return false;
			}
			
			var load = layer.load(2);
			$.post('add.html', $("#form-user-character-add").serialize(), function(data){
				layer.close(load);
				if(data == '操作成功'){
					layer.msg(data, {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    	parent.layer.close(index);
					});
				}else if(data == '请输入管理员密码'){
					var html = '<input type="password" name="pwds" id="pwds" class="input-text radius" />';
					var i = layer.open({
						title: '验证管理员密码',
						content: html,
						yes: function(){
							var password = $("#pwds").val();
							$("#password").val(password);
							layer.close(i);
							$.post('add.html', $("#form-user-character-add").serialize(), function(data){
								if(data == '操作成功'){
									layer.msg(data, {icon: 1, time: 2000}, function(){
										window.parent.location.reload(); //刷新
										var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
										parent.layer.close(index);
									});
								}else{
									layer.msg(data, {icon: 2, time: 2000});
								}
							});
						}
					});
				}else{
					layer.msg(data, {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>